/*
 *  Copyright 2008-2010 www.jrails.org
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.rails.extjs;

import java.util.List;

import org.rails.extjs.javascript.Function;
import org.rails.extjs.javascript.JavaScript;

public class DatePicker extends Component {

	public DatePicker() {
		super();
	}

	public DatePicker(Option configOptions) {
		super(configOptions);
	}

	public DatePicker(String id) {
		super(id);
	}
	
	public void setCancelText(String cancelText){
		addOption("cancelText", cancelText);
	}
	
	public String getCancelText(){
		return getString("cancelText","Cancel");
	}
	
	public void setDayNames(List<String> dayNames){
		addOption("dayNames", dayNames);
	}
	
	@SuppressWarnings("unchecked")
	public List<String> getDayNames(){
		return (List<String>)getOption("dayNames");
	}
	

	public void setDisabledDates(List<String> disabledDates){
		addOption("disabledDates", disabledDates);
	}
	
	@SuppressWarnings("unchecked")
	public List<String> getDisabledDates(){
		return (List<String>)getOption("disabledDates");
	}
	
	public void setDisabledDatesRegex(String disabledDatesRE){
		addOption("disabledDatesRE",new RegExp(disabledDatesRE));
	}
	
	public RegExp getDisabledDatesRegex(){
		return (RegExp)getOption("disabledDatesRE");
	}
	
	public void setDisabledDatesText(String disabledDatesText){
		addOption("disabledDatesText", disabledDatesText);
	}
	
	public String getDisabledDatesText(){
		return getString("disabledDatesText","Disabled");
	}
	
	public void setDisabledDays(List<String> disabledDays){
		addOption("disabledDays", disabledDays);
	}
	
	@SuppressWarnings("unchecked")
	public List<String> getDisabledDays(){
		return (List<String>)getOption("disabledDays");
	}
	
	public void setDisabledDaysText(String disabledDaysText){
		addOption("disabledDaysText", disabledDaysText);
	}
	
	public String getDisabledDaysText(){
		return getString("disabledDaysText", "Disabled");
	}
	
	public void setFormat(String format){
		addOption("format", format);
	}
	
	public String getFormat(){
		return getString("format","");
	}
	
	public void setHandler(Function handler){
		addOption("handler", handler);
	}
	
	public Function getHandler(){
		return (Function)getOption("handler");
	}
	
	public void setMaxDate(JavaScript maxDate){
		addOption("maxDate",maxDate);
	}
	
	public JavaScript getMaxDate(){
		return (JavaScript)getOption("maxDate");
	}
	
	public void setMaxText(String maxText){
		addOption("maxText", maxText);
	}
	
	public String getMaxText(){
		return getString("maxText","This date is after the maximum date");
	}
	
	public void setMinDate(JavaScript minDate){
		addOption("minDate", minDate);
	}
	
	public JavaScript getMinDate(){
		return (JavaScript)getOption("minDate");
	}
	
	public void setMinText(String minText){
		addOption("minText", minText);
	}
	
	public String getMinText(){
		return getString("minText","This date is before the minimum date");
	}
	
	public void setMonthNames(List<String> monthNames){
		addOption("monthNames", monthNames);
	}
	
	@SuppressWarnings("unchecked")
	public List<String> getMonthNames(){
		return (List<String>)getOption("monthNames");
	}
	
	public void setMonthYearText(String monthYearText){
		addOption("monthYearText", monthYearText);
	}
	
	public String getMonthYearText(){
		return getString("monthYearText","Choose a month (Control+Up/Down to move years)");
	}
	
	public void setNextText(String nextText){
		addOption("nextText", nextText);
	}
	
	public String getNextText(){
		return getString("nextText","Next Month (Control+Right)");
	}
	
	public void setOkText(String okText){
		addOption("okText", okText);
	}
	
	public String getOkText(){
		return getString("okText","OK");
	}
	
	public void setPrevText(String prevText){
		addOption("prevText", prevText);
	}
	
	public String getPrevText(){
		return getString("prevText","Previous Month (Control+Left)");
	}
	
	public void setShowToday(Boolean showToday){
		addOption("showToday", showToday);
	}
	
	public Boolean isShowToday(){
		return getBoolean("showToday",true);
	}
	
	public void setStartDay(Integer startDay){
		addOption("startDay", startDay);
	}
	
	
	public Integer getStartDay(){
		return getInteger("startDay",0);
	}
	
	public void setTodayText(String todayText){
		addOption("todayText", todayText);
	}
	
	public String getTodayText(){
		return getString("todayText","Today");
	}
	
	public void setTodayTip(String todayTip){
		addOption("todayTip", todayTip);
	}
	
	public String getTodayTip(){
		return getString("todayTip", "{current date} (Spacebar)");
	}
	
	
	@Override
	public String getScript() {
		script = new StringBuffer("");
		createItems();
		script.append("new Ext.DatePicker(");
		script.append(createOptions());
		script.append(")");
		return script.toString();
	}

}
